package com.app.manage.moudles.system.contoller;

import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.json.JSONObject;
import com.app.manage.moudles.system.entity.TUser;
import com.app.manage.moudles.system.service.TUserService;
import com.app.manage.utils.Rsp;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("user")
@Api(tags = "用户")
@Slf4j
public class UserController {

    @Resource
    private TUserService tUserService;

    @PostMapping("login")
    public Rsp login(String username,String password){
        try {
            TUser tUser = tUserService.loginUser(username,
                    password);
            StpUtil.login(tUser.getId());
            return Rsp.success(StpUtil.getTokenValue());
        }catch (Exception e){
            e.printStackTrace();
            return Rsp.fail(e.getMessage());
        }
    }

    @GetMapping("test")
    public Rsp test(){
        int i = 1/0;
        return Rsp.success();
    }
}
